package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.HashMap;


public class Library {
    public HashMap<Integer, Book> booksList;
    private PrintStream printStream;
    private HashMap<Integer, Movie> movieList;

    public Library(PrintStream printStream) {
        this.printStream = printStream;
        this.booksList = new HashMap<Integer, Book>();

            booksList.put(1, new Book("To Kill A Mocking Bird", false));
            booksList.put(2, new Book("Nobody is Dumb", false));

        this.movieList = new HashMap<Integer, Movie>();

            movieList.put(1 , new Movie("Sholay", 1975 , "Ramesh Sippy", "N/A"));
            movieList.put(2, new Movie("The Sixth Sense", 1999 , "M. Night Shyamalan", "9"));
            movieList.put(3, new Movie("Gravity", 2013, "Alfonso Quaron", "N/A"));
            movieList.put(4, new Movie("Insidious: Chapter 2", 2013 , "James Wan", "3"));
            movieList.put(5, new Movie("Captin Phillips", 2013 , "Paul Grenngrass", "9"));
            movieList.put(6, new Movie("Forrest Bump", 1994 , "Robert Zemeckis", "7"));
            movieList.put(7, new Movie("The mist", 2007 , "Frank Darabont", "7"));
            movieList.put(8, new Movie("12 Years a Slaver", 2013 , "Steve McQueen", "9"));
            movieList.put(9, new Movie("After Earth", 2013 , "M. Night Shyamalan", "1"));
            movieList.put(10, new Movie("Toy Story", 1995 , "John Lasseter", "10"));
            movieList.put(11, new Movie("The boy in the Striped Pajamas", 2008 , "Mark Herman", "6"));
            movieList.put(12, new Movie("Jo Jo Dancer", 1989 , "Richard Pryor", "5"));
            movieList.put(13, new Movie("Our life could be a movie", 1972 , "Susana Rodriguez", "9"));
            movieList.put(14, new Movie("The moview", 2000 , "Janei Summers", "2"));


    }

    public void printListOfAllBooks() {
        String outputString = "";
        for (Integer bookId : booksList.keySet()) {

            outputString += bookId + " "+ booksList.get(bookId).title + "\n";
        }
        printStream.print(outputString);
    }

    public void reserveBook(int bookId) {

        if(booksList.containsKey(bookId)){
            booksList.get(bookId).isReserved = true;
            printStream.println("Thank You! Enjoy the book.");
        }else{
            printStream.println( "Sorry we don't have that book yet.");
        }

    }

    public void printListOfMovies() {

        String outputString = "";
        for (Integer id : movieList.keySet()) {

            outputString += id + " "
                            + movieList.get(id).title + " "
                            +movieList.get(id).year+ "    "
                            +movieList.get(id).director + " "
                            +movieList.get(id).rating + "\n";
        }
        printStream.println("  Movie   Year  Director    Rating");
        printStream.print(outputString);

    }
}
